package org.baojie.raft.message;

import org.baojie.raft.node.NodeName;
import org.baojie.raft.message.info.MessageInfo;

import java.io.Serializable;

public class VoteRequest extends MessageInfo implements Serializable {

    private static final long serialVersionUID = -4152322458490684331L;

    private int term;
    private NodeName candidateName;
    private int lastLogIndex;
    private int lastLogTerm;

    public VoteRequest() {

    }

    @Override
    public Type type() {
        return Type.AskVote;
    }

    public int getTerm() {
        return term;
    }

    public void setTerm(int term) {
        this.term = term;
    }

    public NodeName getCandidateName() {
        return candidateName;
    }

    public void setCandidateName(NodeName candidateName) {
        this.candidateName = candidateName;
    }

    public int getLastLogIndex() {
        return lastLogIndex;
    }

    public void setLastLogIndex(int lastLogIndex) {
        this.lastLogIndex = lastLogIndex;
    }

    public int getLastLogTerm() {
        return lastLogTerm;
    }

    public void setLastLogTerm(int lastLogTerm) {
        this.lastLogTerm = lastLogTerm;
    }

    @Override
    public String toString() {
        return "VoteRequest{" +
                "term=" + term +
                ", candidateName=" + candidateName +
                ", lastLogIndex=" + lastLogIndex +
                ", lastLogTerm=" + lastLogTerm +
                '}';
    }
}
